/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.fyx.linker.controll;

import java.util.LinkedList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import org.fyx.linker.entity.LinkerLink;

/**
 *
 * @author xljan
 */
@Stateless
public class LinkerLinkFacade extends AbstractFacade<LinkerLink> implements LinkerLinkFacadeLocal {
    @PersistenceContext(unitName = "FyxCorePU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public LinkerLinkFacade() {
        super(LinkerLink.class);
    }

    @Override
    /**
     * Return list LinkerLink with defined idCategory.
     * When result list is empty, return empty list.
     */
    public List<LinkerLink> findByIdCategory(int idCategory) {
        try{
            return em.createNamedQuery(
                    LinkerLink.NQ_FIND_BY_ID_CATEGORY, LinkerLink.class).
                    setParameter("idCategory", idCategory).getResultList();
        }catch(NoResultException ex){
            return new LinkedList<LinkerLink>();
        }
    }

    @Override
    public void removeAll() {
        em.createNamedQuery(LinkerLink.NQ_REMOVE_ALL).executeUpdate();
    }
    
}
